/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.ddl.table.controller;

import com.snail.server.database.engine.ddl.table.dto.TableAlterDTO;
import com.snail.server.database.engine.ddl.table.dto.TableCreateDTO;
import com.snail.server.database.engine.ddl.table.manager.TableManager;
import com.snail.server.database.engine.ddl.table.vo.TableVO;
import com.snail.starter.iam.annotation.IgnoreToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 * @author zgadmin
 * @date 2025/8/29 14:29
 *
 */
@Api(tags = {"表管理"})
@RestController
@RequestMapping("/data-source/{dataSourceId}/table")
public class TableController {

    @Resource
    TableManager tableManager;

    @ApiOperation("创建表")
    @PostMapping
    @IgnoreToken
    public Long create(@PathVariable("dataSourceId") Long dataSourceId, @RequestBody TableCreateDTO tableCreate){
        return tableManager.create(dataSourceId, tableCreate);
    }

    @ApiOperation("修改表")
    @PutMapping("/{tableId}")
    @IgnoreToken
    public boolean alter(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @RequestBody TableAlterDTO tableAlter){
        return tableManager.alter(dataSourceId, tableId, tableAlter);
    }

    @ApiOperation("删除表")
    @DeleteMapping("/{tableId}")
    @IgnoreToken
    public boolean deleteById(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId){
        return tableManager.delete(dataSourceId, tableId);
    }

    @ApiOperation("查询表")
    @GetMapping("/{tableId}")
    @IgnoreToken
    public TableVO queryById(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId){
        return tableManager.queryById(dataSourceId, tableId);
    }

}